/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    2013 year
 *    Author: Esipenko Aleksey (Alexorleon)
 *    E-Mail: alexorleon@gmail.com
 */
#ifndef TABLEMODEL_H
#define TABLEMODEL_H


#include "zipcodeitem.h"
#include <QAbstractTableModel>
#include <QStringList>

class TableModel : public QAbstractTableModel
{
    Q_OBJECT

public:
    explicit TableModel(QObject *parent=0)
        : QAbstractTableModel(parent){}

    Qt::ItemFlags flags(const QModelIndex &index) const;
    QVariant data(const QModelIndex &index,
                  int role=Qt::DisplayRole) const;
    QVariant headerData(int section, Qt::Orientation orientation,
                        int role=Qt::DisplayRole) const;
    int rowCount(const QModelIndex &parent=QModelIndex()) const;
    int columnCount(const QModelIndex &parent=QModelIndex()) const;

    bool setData(const QModelIndex &index, const QVariant &value,
                 int role=Qt::EditRole);
    bool setHeaderData(int, Qt::Orientation, const QVariant&,
                       int=Qt::EditRole) { return false; }

    //bool insertRows(int row, int count,
    //                const QModelIndex &parent=QModelIndex());
    bool removeRows(int row, int count,
                    const QModelIndex &parent=QModelIndex());

    //QString filename() const { return m_filename; }
    //void load(const QString &filename=QString());
    void addData(const int &id, const QStringList &list);
    void modelClear(){ zipcodes.clear(); }
    void resetModel();
    bool rowsIsHave() const;
    QList<int> listRows() const;
    QStringList listRowsPath() const;
    //void save(const QString &filename=QString());

    void test();
private:
    QStringList m_list;
    QList<ZipcodeItem> zipcodes;
};

#endif // TABLEMODEL_H
